package com.panshi.controller.leave;

import com.panshi.api.ILeaveApi;
import com.panshi.po.LeavePO;
import com.panshi.po.UserPO;
import com.panshi.vo.PageBeanLeaveVo;
import com.panshi.vo.PageModel;
import com.panshi.vo.QueryDimLeaveVO;
import com.panshi.vo.QueryDimVO;
import com.sun.imageio.plugins.common.I18N;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 用户留言
 */
@Controller
@Slf4j
public class LeaveController {

    @Autowired
    private ILeaveApi leaveApi;

    /**
     * 跳转页面
     * @return
     */
    @GetMapping("queryes")
    public  String query(){

        return "leave/leave-query";
    }


    /**
     * 查询全部信息
     * @param pw
     * @return
     */
    @PostMapping("leave-queryall")
    @ResponseBody
    public PageModel<LeavePO> queryall(PageModel<LeavePO> pw){

        pw.init();
        PageBeanLeaveVo pageBeanLeaveVo=new PageBeanLeaveVo();
        pageBeanLeaveVo.setCurrentPage(pw.getCurrentPage());
        pageBeanLeaveVo.setPageSize(pw.getPageSize());
        log.info("pageBeanLeaveVo========{}",pageBeanLeaveVo);

       List<LeavePO> list=leaveApi.queryLeavePostBody(pageBeanLeaveVo).getData();
        log.info("list=========={}",list);
       Integer integer= leaveApi.queryNumberLeavePostBody().getData();
        log.info("integer========={}",integer);
       pw.setCount(integer);
       pw.setList(list);
       return pw;
    }


    /**
     * 根据联系人模糊查询信息
     * @param pw
     * @param attn
     * @return
     */
    @PostMapping("leave-queryDim/{attn}")
    @ResponseBody
    public PageModel<LeavePO> queryDim(PageModel<LeavePO> pw, @PathVariable String attn){
        QueryDimLeaveVO queryDimVO=new QueryDimLeaveVO();
        queryDimVO.setAttn(attn);
        queryDimVO.setCurrentPage(pw.getCurrentPage());
        queryDimVO.setPageSize(pw.getPageSize());
        log.info("queryDimVO========={}",queryDimVO);
       List<LeavePO> list= leaveApi.queryDimAttnLeavePostBody(queryDimVO).getData();
        log.info("listDim========={}",list);

      Integer integer=  leaveApi.queryDimNumberLeavePostBody(attn).getData();
        log.info("integer========={}",integer);
        pw.setCount(integer);
        pw.setList(list);
       return  pw;
    }


}
